﻿<%@ Application Language="C#" %>

<script RunAt="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
    }

    /// <summary>
    /// 在出现未处理的错误时运行的代码
    /// </summary>
    public void Application_Error(object sender, EventArgs e)
    {
       Exception objErr = Server.GetLastError().GetBaseException();  //获取错误
        string err = "Error Caught in Application_Error event\n" +
        "Error in:" + Request.Url.ToString() +
        "\nError Message:" + objErr.Message.ToString() +
        "\nStack Trace:" + objErr.StackTrace.ToString();
        Application["ErrorUrl"] = Request.Url.ToString();
        Application["Error"] = objErr;
        //将捕获的错误写入windows的应用程序日志中，可从事件查看器中访问应用程序日志。
        System.Diagnostics.EventLog.WriteEntry("50Actions web", err, System.Diagnostics.EventLogEntryType.Error);
    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
    }
       
</script>

